//
// Created by Dell on 2021/12/5.
//
#include<bits/stdc++.h>
using namespace std;
int n,k,x;
vector<int>digit;
vector<int>ans;
vector<int>vis(1000);
void dfs(int cnt,int index,vector<int>digit,int ans){
    if(cnt == 0){
        ans.push(ans);
        return;
    }
    for(int i = index;i<digit.size();++i){
        if(vis[i]) continue;
        vis[i] = 1;
        dfs(cnt+1,i,digit,ans*10+digit[i]);

    }
}



int main(){
    cin>>n;
    for(int i = 0;i<n;++i){
        int tem;
        cin>>tem;
        digit.push_back(tem);

    }
    dfs(0,0,digit,0);
    sort(ans.begin(),ans.end());

    return 0;
}

